{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <!-- Panel Other -->
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>等级申请列表</h5>
        </div>
        <div class="ibox-content">
            <!--搜索框开始-->           
            <!--<div class="row">
                <div class="col-sm-12">
                    <form name="admin_list_sea" class="form-search" method="post" action="{:url('index')}">
                        <div class="col-sm-3">
                            <div class="input-group">
                                <input type="text" id="key" class="form-control" name="username-like" value="{$username|default=''}" placeholder="输入需查询的用户名" />
                                <span class="input-group-btn"> 
                                    <button type="submit" class="btn btn-primary"><i class="fa fa-search"></i> 搜索</button> 
                                </span>
                            </div>
                        </div>
                    </form>                         
                </div>
            </div>-->
            <!--搜索框结束-->
            <!--<div class="hr-line-dashed"></div>-->

            <div class="example-wrap">
                <div class="example">
                    <table class="table table-bordered table-hover">
                        <thead>
                            <tr class="long-tr">
                                <th>微信名</th>
                                <th>当前等级</th>
                                <th>申请等级</th>
                                <th>审核类型</th>
                                <th>审核状态</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody id="list-content">
                            {foreach $list as $vo}
                                <tr class="long-td">
                                    <td>{$vo.nickname}</td>
                                    <td>{:getEnumString(config('enum.customerCurrentLevel'), $vo.from_level)}</td>
                                    <td>{:getEnumString(config('enum.customerCurrentLevel'), $vo.to_level)}</td>
                                    <td>{:getEnumString(config('enum.levelAccessType'), $vo.access_type)}</td>
                                    <td>{:getEnumString(config('enum.levelApplyStatus'), $vo.status)}</td>
                                    <td>
                                        {if $vo.status == config('enum.levelApplyStatus.init.value')}
                                            <a href="javascript:;" onclick="changeLevel('{$vo.to_level}', '{$vo.customer_id}', '{$vo.id}')" class="btn btn-info btn-xs" type="button">
                                                <i class="fa fa-check"></i> 审核通过</a>&nbsp;&nbsp;
                                        {else /}
                                            <font style="color:green">已审核</font>
                                        {/if}
                                    </td>
                                </tr>
                            {/foreach}
                        </tbody>
                    </table>
                </div>
            </div>
            <!-- End Example Pagination -->
        </div>
    </div>
</div>
<!-- End Panel Other -->
</div>

{include file="public/footer" /}
<script type="text/javascript">
function changeLevel(toLevel, customerId, applyId) {

    $.ajax({
        url: "{:url('customer/checkCurrentLevel')}",
        type: "post",
        data: {
            current_level: toLevel,
            customer_id: customerId
        },
        dataType: "json",
        beforeSend:function() {
            // 显示loading
            index2 = layer.load(0, {
                shade: [0.3,'#fff']
            });
        },
        success:function(data) {

            if (data['code'] != 1) {

                // 如果data等于 confirm 表示需要谈 确认框
                if (data['data'] == 'confirm') {
                    layer.confirm(data.msg, {icon: 3}, function(index){
                        changeLevelPost(toLevel, customerId, applyId);
                    });
                    return false;
                }

                layer.msg(data.msg,{icon:2,time:1000,shade: 0.1,}, function(index){
                    layer.close(index)
                });
                return false;
            }

            layer.confirm(data.msg, {icon: 3}, function(index){
                changeLevelPost(toLevel, customerId, applyId)
            });
        },
        complete:function() {
            // 隐藏loading
            layer.close(index2);
        }
    });
}

function changeLevelPost(currentLevel, customerId, applyId) {

    $.ajax({
        url: "{:url('changeCustomerLevel')}",
        type: "post",
        data: {
            current_level: currentLevel,
            customer_id: customerId,
            apply_id: applyId
        },
        dataType: "json",
        beforeSend:function() {
            // 显示loading
            index2 = layer.load(0, {
                shade: [0.3,'#fff']
            });
        },
        success:function(data) {

            if (data['code'] != 1) {

                layer.msg(data.msg,{icon:2,time:1000,shade: 0.1,}, function(index){
                    layer.close(index)
                });
                return false;
            }

            layer.msg(data.msg, {icon: 1,time:1000,shade:0.1}, function(index) {
                window.location.reload();
            });
        },
        complete:function() {
            // 隐藏loading
            layer.close(index2);
        }
    });
}

</script>

</body>
</html>